//
//  XJCtySecondPageClvItem.m
//  XinJiangMall
//
//  Created by RaoBo on 2018/6/9.
//  Copyright © 2018年 Tzyang. All rights reserved.
//

#import "XJCtySecondPageClvItem.h"
@interface XJCtySecondPageClvItem()
@property(nonatomic, strong) UIView *bgView;
@property(nonatomic, strong) UIImageView *iconIv;
@property(nonatomic, strong) UILabel *nameLb;
@property(nonatomic, strong) UILabel *priceLb;
@property(nonatomic, strong) UILabel *marketPriceLb;


@end

@implementation XJCtySecondPageClvItem

#pragma mark - 一 lazy
- (UIView *)bgView {
    if (!_bgView) {
        _bgView = [UIView new];
    }
    return _bgView;
}

- (UIImageView *)iconIv {
    if (!_iconIv) {
        _iconIv = [UIImageView new];
        _iconIv.layer.masksToBounds = YES;
        _iconIv.layer.cornerRadius = 5;
     }
    return _iconIv;
}
- (UILabel *)nameLb{
    if (!_nameLb) {
        _nameLb = [UILabel new];
        _nameLb.font = XJFONTSET_R(13.0);
        _nameLb.numberOfLines = 0;
     }
    return _nameLb;
}

- (UILabel *)priceLb{
    if (!_priceLb) {
        _priceLb = [UILabel new];
        _priceLb.font = XJFONTSET_R(13.0);
     }
    return _priceLb;
}
- (UILabel *)marketPriceLb {
    if (!_marketPriceLb) {
        _marketPriceLb = [UILabel new];
        _marketPriceLb.font = XJFONTSET_R(13.0);

        _marketPriceLb.textAlignment = NSTextAlignmentRight;
        _marketPriceLb.textColor = [UIColor lightGrayColor];
     }
    return _marketPriceLb;
}

#pragma mark - 二 初始化
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setupView];
    }
    return self;
}

- (void)setupView {
    [self.contentView addSubview:self.bgView];
    [self.bgView addSubview:self.iconIv];
    [self.bgView addSubview:self.nameLb];
    [self.bgView addSubview:self.priceLb];
    [self.bgView addSubview:self.marketPriceLb];
}


#pragma mark - 三 layout
- (void)layoutSubviews {
    [super layoutSubviews];

    CGFloat k5 = 5;
    [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.contentView);
    }];
    
    CGFloat iconIv_w = (KWidth - 10-20) / 2;
    
    [self.iconIv mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.bgView);
        make.size.mas_equalTo(CGSizeMake(iconIv_w, iconIv_w));
        make.centerX.equalTo(self.bgView.mas_centerX);
    }];
    
    [self.nameLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.iconIv.mas_bottom).offset(k5);
        make.left.equalTo(self.iconIv.mas_left);
        make.right.equalTo(self.iconIv.mas_right);
        make.height.mas_equalTo(40);
    }];
    
    [self.priceLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.nameLb.mas_bottom).offset(k5);
        make.left.equalTo(self.nameLb.mas_left);
        make.size.mas_equalTo(CGSizeMake(60, 20));
    }];
    
    [self.marketPriceLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.nameLb.mas_bottom).offset(k5);
        make.right.equalTo(self.iconIv.mas_right);
        make.size.mas_equalTo(CGSizeMake(80, 20));
    }];
}


#pragma mark - 四 configure
- (void)configureCtySecondPageClvItemWithIcon:(NSString *)icon name:(NSString *)name price:(NSString *)price marketPrice:(NSString *)marketPrice {
    UIImage *placehoder = [UIImage imageNamed:@"default_goods"];
    
    [self.iconIv sd_setImageWithURL:[NSURL URLWithString:icon] placeholderImage:placehoder];
    
    self.nameLb.text = name;
    
    self.priceLb.text = [NSString stringWithFormat:@"￥%.2f",[price floatValue]];
    
    NSString * marketPriceStr = [NSString stringWithFormat:@"￥%.2f",[marketPrice floatValue]];
    
    NSDictionary *attributeDic = @{NSStrikethroughStyleAttributeName:[NSNumber numberWithInteger:NSUnderlineStyleSingle]};
    NSMutableAttributedString *attributeStr = [[NSMutableAttributedString alloc] initWithString:marketPriceStr attributes:attributeDic];
    
    self.marketPriceLb.attributedText = attributeStr;
}




@end
